#include <iostream>
#include <memory>

using namespace std;
class MyClass : public std::enable_shared_from_this<MyClass>
{

public:
    std::shared_ptr<MyClass> getShared()
    {
        return shared_from_this();
    }
    void show()
    {
        std::cout << "Hello, I'm a MyClass instance" << std::endl;
    }
};

int main()
{
    std::shared_ptr<MyClass> p = std::make_shared<MyClass>();
    std::shared_ptr<MyClass> p2 = p->getShared(); // p2是p的另一个shared_ptr实例，引用计数为2
    p2->show();                                   // Output: Hello, I'm a MyClass instance

    shared_ptr<MyClass> p3 = p; // 直接赋值，引用计数为3
}
